﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace Demo0621
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            //在HttpApplication类的第一个实例创建时，该事件被触发。
            Application["OnlinNum"] = 0;//在线人数
            Application["VisitNum"] = 0;//总访问人数
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            //每次新会话开始时触发
            Application["OnlinNum"] = int.Parse(Application["OnlinNum"].ToString()) + 1;//在线人数+1
            Application["VisitNum"] = int.Parse(Application["VisitNum"].ToString()) + 1;//总人数+1
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            //每次页面请求开始时触发

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            //会话结束时触发
            Application["OnlinNum"] = int.Parse(Application["OnlinNum"].ToString()) - 1;//在线人数-1
        }

        protected void Application_End(object sender, EventArgs e)
        {
            //在HttpApplication类的最后一个实例销毁时，该事件被触发。在一个应用程序的生命周期内，它只被触发一次。
        }
    }
}